home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEMP / GNU / bison / MfcalcRulf < prev    next >
Text File  |  1995-06-28  |  1KB  |  40 lines

  1. Mfcalc Rules
  2. Previous: <Mfcalc Decl=>MfcalcDecm> * Next: <Mfcalc Symtab=>MfcalcSymu> * Up: <Multi-function Calc=>Multifunct>
  3.  
  4. #Wrap on
  5. {fH4}Grammar Rules for {fCode}mfcalc{f}{f}
  6.  
  7. Here are the grammar rules for the multi-function calculator.
  8. Most of them are copied directly from {fCode}calc{f}; three rules,
  9. those which mention {fCode}VAR{f} or {fCode}FNCT{f}, are new.
  10.  
  11. #Wrap off
  12. #fCode
  13. input:   \/\* empty \*\/
  14.         | input line
  15. ;
  16.  
  17. line:
  18.           '\\n'
  19.         | exp '\\n'   \{ printf ("\\t%.10g\\n", $1); \}
  20.         | error '\\n' \{ yyerrok;                  \}
  21. ;
  22.  
  23. exp:      NUM                \{ $$ = $1;                         \}
  24.         | VAR                \{ $$ = $1->value.var;              \}
  25.         | VAR '=' exp        \{ $$ = $3; $1->value.var = $3;     \}
  26.         | FNCT '(' exp ')'   \{ $$ = (\*($1->value.fnctptr))($3); \}
  27.         | exp '+' exp        \{ $$ = $1 + $3;                    \}
  28.         | exp '-' exp        \{ $$ = $1 - $3;                    \}
  29.         | exp '\*' exp        \{ $$ = $1 \* $3;                    \}
  30.         | exp '\/' exp        \{ $$ = $1 \/ $3;                    \}
  31.         | '-' exp  %prec NEG \{ $$ = -$2;                        \}
  32.         | exp '^' exp        \{ $$ = pow ($1, $3);               \}
  33.         | '(' exp ')'        \{ $$ = $2;                         \}
  34. ;
  35. \/\* End of grammar \*\/
  36. %%
  37. #f
  38. #Wrap on
  39.  
  40.